<?php 
/**
 * 下架状态为
 * @return array
 * 
 */
function lineDownAlertProductType()
{
    return array(
        '1'=>'景区',
        '2'=>'酒店',
        '3'=>'线路'
    );
}

/**
 *  合作单位数组
 *  @return array
 */
function collaborateTypeArray()
{
    return array(
        '1'=>'合作景区',
        '2'=>'合作旅行社',
        '3'=>'合作淘宝店',
        '4'=>'热门电子商务平台'
    );
}

/**
 *  议价结算方式
 *  @return array
 */
function bargainingNode(){
    return array(
        'system'  =>'系统结算',
        'private' =>'自主结算'
    );
}

/**
 *  议价手续费付费方式
 *  @return array
 */
function bargainingPayer(){
    return array(
            'seller'    => '分销商付手续费',
            'provider'  => '供应商',
            'prosecond' => '二级供应商'
    );
}

/**
 * 着想科技服务页面幻灯片数组
 * @return array
 */
function collaboratesTypeArray()
{
	return array(
		  '1'=>'首页图片',
	      '2'=>'系统介绍',
	      '3'=>'销售申请',
	      '4'=>'供应申请',
	      '5'=>'服务申请',
	      '6'=>'系统流程',
	      '7'=>'应用案例',
	      '8'=>'合作单位',
	      '9'=>'常见问题',
	      '10'=>'招商加盟',
	);
}

/**
 * 着想系统前端所属页面
 * @return array
 */
function pageBelongArray()
{
	return array(
	    '2'=>'系统介绍',
        '3'=>'服务申请',
        '4'=>'供应申请',
        '5'=>'销售申请',
        '7'=>'应用案例',
        '8'=>'系统教程',
        '9'=>'常见问答',
	    '10'=>'招商加盟'
	);
}

/**
 * 帮助中心编辑页面
 * @return array
 */
function typePageArray()
{
	return array(
		'2'=>'门票预订',
	    '3'=>'酒店预订',
	    '4'=>'支付常见问题',
	    '5'=>'关于退订和投诉'
	);
}


/**
 * 着想系统加盟申请
 * @return array
 */
function applyArray(){
	
    return array(
            '4'=>'分销商申请',
            '5'=>'加盟商申请',
            '6'=>'区域代理申请',
    );
}

/**
 * 获取cmsBlock描述。
 * @param string $blockId
 * @return string
 */
function cmsBlock($blockId)
{
    $CI = & get_instance();
    $CI->load->model('cms_block_model', 'cms_block');
    $result = $CI->cms_block->findByBlockId($blockId);
    $description = '';
    if ($result) {
        $description = $result->row(0)->description;
    }
    return $description;
}

/**
 * topmenu线路旅游类型
 * @return array
 */
function lineTravelType($type = false)
{
    $CI = & get_instance();
    $CI->load->model('line_travel_type_model', 'line_travel_type');
    $result = $CI->line_travel_type->find();
    if ($type) {
        $rows = array();
        foreach ($result->result_array() as $row) {
            $rows[$row['id']] = $row;
        }
        return $rows;
    }
    return $result->result();
}

/**
 * 线路产品名称展示
 * @return array
 */
function lineProductType($type = false)
{
    $CI = & get_instance();
    $CI->load->model('line_product_type_model', 'line_product_type');
    $result = $CI->line_product_type->find();
    if ($type) {
        $rows = array();
        foreach ($result->result_array() as $row) {
            $rows[$row['id']] = $row;
        }
        return $rows;
    }
    return $result->result();
}

/**
 * 线路往返交通展示
 * @return array
 */
function lineTraffic($type = false)
{
    $CI = & get_instance();
    $CI->load->model('line_traffic_model', 'line_traffic');
    $result = $CI->line_traffic->find();
    if ($type) {
        $rows = array();
        foreach ($result->result_array() as $row) {
            $rows[$row['id']] = $row;
        }
        return $rows;
    }
    return $result->result();
}

/**
 * 
 * @param unknown $priv_str
 * @return boolean
 */
function admin_permission($priv_str)
{
    $CI = & get_instance();
    $action_list = $CI->session->userdata('action_list');
    $action_new = explode(',', $action_list);
    if (!in_array($priv_str, $action_new, TRUE)) {
        return false;
    } 

    return true;
}

/**
 * 线路订单状态
 * @return array
 */
function lineOrderStatusArray()
{
    return array(
        '1'=>'待确认',
        '2'=>'已确认',
        '3'=>'已取消',
        '4'=>'已付款',
        '5'=>'已完成',
        '6'=>'已退款',
        '7'=>'过期订单',
    );
}

/**
 * 线路支付状态
 * @return array
 */
function lineOrderStateArray()
{
    return array(
        '1'=>'未支付',
        '2'=>'已支付',
        '3'=>'已完成',
        '4'=>'已退款'
    );
}

/**
 * 线路支付类型
 * @return array
 */
function linePayStyleTypeArray($type = false)
{
    $CI = & get_instance();
    $CI->load->model('pay_style_model', 'pay_style');
    $result = $CI->pay_style->find();
    if ($type) {
        $rows = array();
        foreach ($result->result_array() as $row) {
            $rows[$row['id']] = $row;
        }
        return $rows;
    }
    return $result->result();
}

/**
 * 酒店层级太多  传的参数也太多 
 * @return array
 */
function getHotelUrl($key)
{
    $data = array(
            '1'=> array('hotel_id'),  //房型
            '2'=> array('hotel_id', 'room_id'),   ///房间
            '3'=> array('hotel_id', 'room_id', 'goods_id'), //房间产品
            '4'=> array('hotel_id', 'room_id', 'goods_id', 'year', 'month'), //房价价格
            '5'=> array('hotel_id', 'room_id', 'goods_id', 'year', 'month', 'nightly_id'), //议价添加
    );
    return urlGetParam($data[$key]); 
}

/**
 * 酒店url get传参
 * @param unknown $getParam
 */
function urlGetParam($getParam, $state = false)
{
    $suffix = array();
    foreach ($getParam as $value){
        if (isset($_GET[$value])){
            $suffix[$value] = $_GET[$value];
        } elseif ( isset($_POST[$value]) ) {
            $suffix[$value] = $_POST[$value];
        }
    }

    if ( $state == 1 ) {
        return $suffix;
    }
    $param = '';
    if ( $getParam ) {
        $param = http_build_query($suffix);
    }
    return $param;
}

/**
 * 酒店产品来源数组
 * @return array
 */
function hotelSourceArray()
{
	return array(
		'1'=>'着想',
		'2'=>'艺龙'
	);
}

/**
 * 酒店房型--宽带
 * @return multitype:string
 */
function hotelMarkType()
{
    return array(
            '1' => '商圈',
            '2' => '行政区域',
            '3' => '机场火车站',
            '4' => '地铁站',
            '5' => '大学',
            '6' => '周边游',
    );
}

/**
 * 酒店入住时间
 */
function checkInTime(){
    $data = array(
            '12' => '12:00',
            '13' => '13:00',
            '14' => '14:00',
            '15' => '15:00',
            '16' => '16:00',
            '17' => '17:00',
            '18' => '18:00',
            '19' => '19:00',
            '20' => '20:00',
            '21' => '21:00',
            '22' => '22:00',
            '23' => '23:00',
            '00' => '00:00',
            '01' => '01:00',
            '02' => '02:00',
            '03' => '03:00',
            '04' => '04:00',
            '05' => '05:00',
            '06' => '06:00',
    );
    return $data;
}

/**
 * 酒店离店时间
 */
function checkOutTime(){
    $data = array(
            '00' => '00:00',
            '01' => '01:00',
            '02' => '02:00',
            '03' => '03:00',
            '04' => '04:00',
            '05' => '05:00',
            '06' => '06:00',
            '07' => '07:00',
            '08' => '08:00',
            '09' => '09:00',
            '10' => '10:00',
            '11' => '11:00',
            '12' => '12:00',
            '13' => '13:00',
            '14' => '14:00',
            '15' => '15:00',
            '16' => '16:00',
            '17' => '17:00',
            '18' => '18:00',
            '19' => '19:00',
            '20' => '20:00',
            '21' => '21:00',
            '22' => '22:00',
            '23' => '23:00',
    );
    return $data;
}

/**
 * 酒店图片类型
 */
function hotelImageType()
{
	return array(
	        '1'  => '外景',
	        '2'  => '内景 ',
	        '3'  => '房间 '
	);
}


/**
 * 地区类型
 *
 */
function regionType()
{
    return array(
            '0'=>'国家',
            '1'=>'省份',
            '2'=>'城市',
            '3'=>'县/区'
    );
}

/**
 * 酒店价格审核状态位
 *
 */
   function roomPriceflagArray()
   { 
       return array(
       	     '0'=>'未处理',
             '1'=>'通过',
             '2'=>'驳回'
       );
   }
   
   /**
    * 酒店销售状态
    *
    */
   function hotelstate()
   {
       return array(
               'Y'  => '可销售',
               'N'  => '不可销售'
       );
   }
   
   /**
    * 酒店宽带情况
    *
    */
   function hotelBroadne()
   {
       return array(
           '1' => '免费wifi',
           '2' => '收费wifi',
           '3' => '免费宽带',
           '4' => '收费宽带',
           '5' => '不能上网'
       );
   }
   
   /**
    * 酒店早餐
    *
    */
   function hotelBreakfastAmoun()
   {
       return array(
               '0' => '不含早',
               '1' => '单早',
               '2' => '双早',
               '3' => '多早',
       );
   }
   
   /**
    * 酒店订单状态
    *
    */
   function hotelOrderStatus()
   {
       return array(
               '1' => '未付款',
               '2' => '待酒店确认(已付款)',
               '3' => '已确认',
               '4' => '已完成',
               '5' => '已退款',
               '6' => '过期订单'
       );
   }
   
   /**
    * 酒店支付方式
    *
    */
   function paymenttype()
   {
       return array(
      	   	    'prepay'  => '在线支付',
      	        'selfpay' => '前台支付',
      	        'all'     => '全部'
       );
   }

   /**
    * 酒店类型
    *
    */
   function hotelStarRate()
   {
       return array(
            '1' => '经济/客栈',
            '2' => '三星/舒适',
            '3' => '四星/高档',
            '4' => '五星/豪华',
            '5' => '公寓'
       );
   }
   
   /**
    * 酒店图片类型
    *
    */
   function hotelImageSize()
   {
       return array(
              '1' => array('width' => 130, 'height' => 130),
              '2' => array('width' => 300, 'height' => 225),
              '3' => array('width' => 500, 'height' => 415)
       );
   }

/**
 * 百度日志类别
 */
function baiduLogTypeArray()
{
	return array(
		'1'=>'商品库',
		'2'=>'下单',
		'3'=>'核销',
	    '9'=>'修改',
		'4'=>'退票',
	    '5'=>'查询',
	    '6'=>'校验订单',
	    '7'=>'支付订单',
	    '8'=>'重发凭证'
	);
}

/**
 * 百度订单类别
 */
function baiduOrderTypeArray(){
	return array(
		'1'=>'景区',
		'2'=>'酒店',
		'3'=>'线路'
	);
}

/**
 * 淘宝日志类别
 */
function taobaoLogTypeArray()
{
	return array(
		'send'=>'商家电子凭证发码成功回调接口',
		'resend'=>'外部合作商家重发电子凭证回调接口',
		'consume'=>'电子票券消费通知',
	    'beforeconsume'=>'电子凭证验码前置确认',
		'card_consume'=>'O2O证件核销接口',
		'reverse'=>'电子凭证冲正接口',
		'card_reverse'=>'O2O证件冲正接口',
		'auth_beforeconsume'=>'核销放行的查询接口',
		'cancel'=>'接收退款成功通知',
		'modified'=>'接收用户修改手机通知',
		'order_modify_valid'=>'接收订单有效期修改通知',
		'order_modify_sfz'=>'接收订单身份证修改通知',
		'order_modify_rights'=>'接收订单维权成功通知',
		'order_modify'=>'接收订单修改通知(有效期修改、身份证修改、维权成功)'
	);
}

function account_type($type)
{
    $balance = $type;
    $account_type = array(
        1    => '支付',
        2    => '提现',
        4    => '银行充值',
        8    => '退票',
        16   => '虚拟充值',
        32   => '提现驳回',
        64   => '到付反利',
        128  => '在线利润',
        256  => '月结抵扣',
        512  => '抵扣驳回',
        1024 => '月结转余额'
    );
    if (array_key_exists($type, $account_type)) {
        $balance = $account_type[$type];
    }
    return $balance;
}

/**
 * 日志类别
 */
/*function apiTypeArray()
{
	return array(
		'1'=>'发送订单',
		'2'=>'修改订单',
		'3'=>'退单',
		'4'=>'短信',
		'8'=>'彩信'
	);
}*/
function apiTypeArray()
{
	return array(
		'1'=>'发送订单',
		'2'=>'取消订单',
		'4'=>'发送短信',
		'5'=>'核销订单',
		'8'=>'发送彩信',
		'9'=>'短信转发',
		'10'=>'彩信转发',
		'16'=>'修改订单',
	    '33'=>'审核订单',
	    '35'=>'更新产品'
	);
}

/**
 * 日志状态
 */
function apiFlagArray()
{
	return array(
		'1'=>'成功',
		'2'=>'失败',
        '3'=>'待处理'
	);
}

/**
 * 短信状态
 */
function smsStatuaArray()
{
	return array(
		'100'=>'100发送成功',
		'101'=>'101验证失败',
		'102'=>'102短信不足',
		'103'=>'103操作失败',
		'104'=>'104非法字符',
		'105'=>'105内容过多',
		'106'=>'106号码过多',
		'107'=>'107频率过快',
		'108'=>'108号码内容空',
		'109'=>'109账号冻结',
		'110'=>'110禁止频繁单条发送',
		'111'=>'111系统暂定发送',
		'112'=>'112有错误号码',
		'113'=>'113定时时间不对',
		'114'=>'114账号被锁，10分钟后登录',
		'115'=>'115连接失败',
		'116'=>'116禁止接口发送',
		'117'=>'117绑定IP不正确',
		'120'=>'120系统升级'	
	);
}

/**
 * 反馈类型数组
 * @return array
 */
function userFeedBackTypeArray()
{
    return array(
        '1'=>'使用不畅',
        '2'=>'缺少内容',
        '3'=>'宝贵建议',
    );
}

function getRegionAll()
{
    return array(
        1 => array(
            'state_name' => '华东',
            'level_name' => array(
                '25' => '上海',
                '16' => '江苏',
                '31' => '浙江',
                '3'  => '安徽',
                '17' => '江西',
                '22' => '山东',
                '4'  => '福建',
            ),
        ),
        2=> array(
            'state_name' => '华北',
            'level_name' => array(
                '2'  => '北京',
                '27' => '天津',
                '23' => '山西',
                '10' => '河北',
                '19' => '内蒙古',
            ),
        ),
        3=> array(
            'state_name' => '华中',
            'level_name' => array(
                '14' => '湖南',
                '13' => '湖北',
                '11' => '河南',
            ),
        ),
        4=> array(
            'state_name' => '华南',
            'level_name' => array(
                '6' => '广东',
                '7' => '广西',
                '9' => '海南',
            ),
        ),
        5=> array(
            'state_name' => '东北',
            'level_name' => array(
                '18' => '辽宁',
                '15' => '吉林',
                '12' => '黑龙江',
            ),
        ),
        6=> array(
            'state_name' => '西北',
            'level_name' => array(
                '24' => '陕西',
                '29' => '新疆',
                '5'  => '甘肃',
                '20' => '宁夏',
                '21' => '青海',
            ),
        ),
        7=> array(
            'state_name' => '西南',
            'level_name' => array(
                '32' => '重庆',
                '30' => '云南',
                '8'  => '贵州',
                '28' => '西藏',
                '26' => '四川',
            ),
        ),
        8=> array(
            'state_name' => '港澳台',
            'level_name' => array(
                '33' => '香港',
                '34' => '澳门',
                '35' => '台湾',
            ),
        ),
    );
}

/**
 * 快递当前状态
 * @return array
 */
function expressState()
{
    return array(
        '-1'=> '快递公司未收录',
        '0' => '在途中',
        '1' => '已揽收',
        '2' => '疑难',
        '3' => '已签收',
        '4' => '退签',
        '5' => '同城派送中',
        '6' => '退回',
        '7' => '转单'
    );
}

/**
 * 快递状态
 * @return array
 */
function expressIsCheck()
{
    return array(
        '-1'=> '快递公司未收录',
        '0' => '在途',
        '1' => '揽件',
        '2' => '疑难',
        '3' => '签收'
    );
}

/**
 * 商品快递物流
 * @return array
 */
function tourismLogisticsTypeArray()
{
    return array(
        'ems'            => 'EMS',
        'shunfeng'       => '顺丰速递',
        'shentong'       => '申通速递',
        'yuantong'       => '圆通速递',
        'zhongtong'      => '中通快递',
        'huitongkuaidi'  => '百世汇通',
        'yunda'          => '韵达快递',
        'zhaijisong'     => '宅急送',
        'tiantian'       => '天天快递',
        'guotongkuaidi'  => '国通快递',
        'zengyisudi'     => '增益速递',
        'ztky'           => '中铁物流',
        'zhongtiewuliu'  => '中铁快运',
        'ganzhongnengda' => '能达速递',
        'quanfengkuaidi' => '全峰快递',
        'jd'             => '京东',
        'bjemstckj'      => '北京EMS',
        'huiqiangkuaidi' => '汇强快递',
        'yuntongkuaidi'  => '运通快递',
        'kuaijiesudi'    => '快捷速递',
        'youzhengguonei' => '邮政包裹',
        'debangwuliu'    => '德邦',
        'tiandihuayu'    => '天地华宇',
        'suer'           => '速尔物流',
        'youshuwuliu'    => '优速',
        'yuanchengwuliu' => '远成物流',
        'jiayiwuliu'     => '佳怡物流',
        'longbanwuliu'   => '龙邦物流',
        'hengluwuliu'    => '恒路物流',
        'xinbangwuliu'   => '新邦物流',
        'tnt'            => 'TNT',
        'dhl'            => 'DHL',
        'fedex'          => 'Fedex',
        'ups'            => 'UPS',
        'usps'           => 'USPS',
    );
}

/**
 * 抽奖奖品等级转换
 * @return array
 */
function prizeGrade()
{
    return array(
        1 => '一',
        2 => '二',
        3 => '三',
        4 => '四',
        5 => '五',
        6 => '六',
        7 => '七',
        8 => '八',
        9 => '九'
    );
}

/**
 * 获取抽奖 url
 */
function getLotteryUrl($key = 1, $state = false)
{
    $data = array(
        1 => array('lottery_id', 'lottery_name'),  //抽奖活动id及名称
        2 => array('lottery_id', 'lottery_name', 'prize_id'),  //抽奖活动id及名称
    );
    return urlGetParam($data[$key], $state);
}

/**
 * 投票活动 url
 */
function getActivityVoteUrl($key = 1, $state = false)
{
    $data = array(
        1 => array('vote_id', 'vote_name')  //投票活动id及名称
    );
    return urlGetParam($data[$key], $state);
}

//验证着想链接
function checkBzUrl($link)
{
    //如果链接正确
    if (preg_match('/^((https?):\/\/)?(\w+\.zxkj918.com)(?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*)$/', $link)) {
        return TRUE;
    }
    return FALSE;
}

/**
 * 验证时分
 */
function checkTimeHm($timeHm) {
    if (preg_match('/^(?:(?:0?|1)\d|2[0-3]):[0-5]\d$/', $timeHm)) {
        return TRUE;
    }
    return FALSE;
}

/**
 * 验证日期
 */
function valiDate($date) {
    $time = strtotime($date);
    return $time ? date('Y-m-d', $time) : FALSE;
}


function days_in_month($month, $year) {
    return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}

/**
 * 验证用户登录类型
 * @param unknown $usertype
 * @return multitype:string
 */
function usertype($usertype)
{
    $userInfo = array();
    $bitusers= array(UTID_CUSTOMER, UTID_PROVIDER, UTID_TELLER, UTID_SELLER, UTID_GROWTH, UTID_MANAGER_L2, UTID_MANAGER_L1, UTID_BEIZHU, UTID_PURCHASER);
    foreach ($bitusers as $type) {
        if ((intval($type)& intval($usertype)) != intval($type)) {
            continue;
        }
        switch ($type) {
            case UTID_PROVIDER://供应商
                $userInfo['type_en'] ='provider';
                $userInfo['type_zh'] = '供应商';
                break;
            case UTID_PURCHASER://采购
                $userInfo['type_en'] = 'purchaser';
                $userInfo['type_zh'] = '采购商';
                break;
            case UTID_BEIZHU://着想保留
                $userInfo['type_en'] = 'beizhu';
                $userInfo['type_zh'] = '着想';
                break;
            case UTID_MANAGER_L1://代理
                $userInfo['type_en'] = 'manager_l1';
                $userInfo['type_zh'] = '省级代理';
                break;
            case UTID_MANAGER_L2:
                $userInfo['type_en'] = 'manager_l2';
                $userInfo['type_zh'] = '市级代理';
                break;
            case UTID_GROWTH:
                $userInfo['type_en'] = 'growth';
                $userInfo['type_zh'] = '发展商';
                break;
            case UTID_SELLER:
                $userInfo['type_en'] = 'seller';
                $userInfo['type_zh'] = '分销商';
                break;
            case UTID_CUSTOMER:
                $userInfo['type_en']  = 'customer';
                $userInfo['type_zh']  = '会员';
                break;
            case UTID_TELLER:
                $userInfo['type_en'] = 'teller';
                $userInfo['type_zh'] = '检票员';
                break;
            case UTID_MAC:
                $userInfo['type_en'] = 'mac';
                $userInfo['type_zh'] = '终端机';
            default:
                $userInfo['type_en'] = 'unknow';
                $userInfo['type_zh'] = '未知用户类型';
                break;
        }
    }
    return $userInfo;
}